//流：有方向的数据
const fs = require('fs')
const rs = fs.createReadStream('./readdir.js')

//process.stdout导出到控制台
rs.pipe(process.stdout)


const ws = fs.createWriteStream('./你好啊.txt')

const tid = setInterval(()=>{
    const num = parseInt(Math.random()*10)
    console.log(num)
    if(num<8){
        ws.write(''+num)
    }else {
        clearInterval(tid)
        ws.end()
    }
},500)

ws.on('finish',()=>{
    console.log('done')
})
